import pymysql

# kdtx mysql
# 连接数据库
conn = pymysql.connect(host='211.103.136.244',
                       user='student',
                       password='KDTX_student_202304',
                       database='huike',
                       port=7068,
                       charset='utf8')
# litemall
# conn = pymysql.connect(host='192.168.126.132',
#                        user='root',
#                        password='123456',
#                        database='litemall',
#                        port=3306,
#                        charset='utf8')

# 获取游标对象
cursor = conn.cursor()
#执行sql语句
# cursor.execute('select version()')
cursor.execute('select * from tb_contract')
# 当同时使用时,取一行这取表的第一行,取2行时取的是表的第二行和第三行,取所有行时取得是第四行到最后一行
# 一行
print(cursor.fetchone())
print("--"*100)
# 看参数几行就为几行
print(cursor.fetchmany(2))
print("--"*100)
# 所有行
print(cursor.fetchall())

# cursor.execute('select * from litemall_goods')
# print(cursor.fetchone())
# print(cursor.fetchmany(4))
# print(cursor.fetchall())

# 释放资源
cursor.close()
conn.close()